<%@ page contentType="text/html; charset=utf-8" language="java"
	import="java.sql.*" errorPage=""%>
<%@ page import="javax.jdo.PersistenceManager"%>
<%@ page import="javax.jdo.Query"%>
<%@ page import="java.util.List"%>
<%@ page import="shared.MyDateUtil"%>
<%@ page import="shared.PMF"%>
<%@ page import="activity.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>-Select-</title>
</head>
<body>
	<p>
		<strong>關鍵字</strong>
	</p>

	<form name="form" method="post" action="sear_select.jsp">
		<p>
			<label> 再選擇活動：<select name="select">
				<%
					PersistenceManager pm = PMF.get().getPersistenceManager();
					Query query = pm.newQuery(Activity.class);
					List<Activity> results = (List<Activity>) query.execute();
					for (Activity act : results) {
				%>
				<option value=<%=act.getActShop()%>><%=act.getActShop()%></option>
				<%
					}
				%>
		</select>
		</label>
		</p>

		<label> <input type="submit" value="查詢" />
		
				<input type="hidden" name="search" value="1" /></label>
		
	</form>

	<table>
		<%
		String search = request.getParameter("search");
			if (search != null) {
				PersistenceManager pm2 = PMF.get().getPersistenceManager();
				
				//String select = request.getParameter("select");
				String select = request.getParameter("select");
				//Activity_supply searchActivity;
		
			 	Query q = pm2.newQuery("select from activity.Activity_supply"); //where actShop_s =="+select);	
				try {
					List<Activity_supply> results2 = (List<Activity_supply>) q.execute();
		%>

		<tr>
			<td>ID</td>
			<td>提供商家名稱</td>
			<td>提供活動名稱</td>
			<td>提供活動點數</td>
			<td>集點開始日期</td>
			<td>集點結束日期</td>
			<td>描述</td>
		</tr>

		<%
		 if (!results2.isEmpty()) {
				for (Activity_supply act : results2) {
					if (select.equals(act.getActShop_s())) {
		%>
		<tr>
			<td><%=act.getActID_s()%></td>
			<td><%=act.getActShop_s()%></td>
			<td><%=act.getActName_s()%></td>
			<td><%=act.getActPoint_s()%></td>
			<td><%=act.getActStart_s()%></td>
			<td><%=act.getActEnd_s()%></td>
			<td><%=act.getActContent_s()%></td>
		</tr>
		<%
			} //if    
						} //for			
					} else
						out.println("查無搜尋結果");
				}//try

				finally {
					q.closeAll();
					pm2.close();
					pm.close();
				}
			}//if
			else{
				out.println("尚未搜尋");
			}
		
		%>
	</table>
	<p></p>
</body>
</html>
